package jbstoremgmt.service;

import org.springframework.validation.Validator;
import org.springframework.validation.Errors;
import jbstoremgmt.service.LoginFormBean;


public class LoginFormValidator implements Validator {
	
	public boolean supports(Class clazz)	
	{
		return clazz.equals(LoginFormBean.class);
	}

	public void validate(Object obj, Errors errors)
	{
		LoginFormBean lBean = (LoginFormBean) obj;
		if (lBean == null)
		{
			errors.rejectValue("usrid", "error.login.not-specified", null,"Value required.");
			return;
		} 
		if (lBean.getUsrid()== null || lBean.getUsrid().trim().length() <= 0) {
			errors.rejectValue("usrid", "error.usridblank","User id is Required.");
			return;
		}
		if (lBean.getUsrpwd()== null || lBean.getUsrpwd().trim().length() <= 0)
		{
			errors.rejectValue("usrpwd", "error.passwordblank","Password is Required.");
			return;
		}
		// Check if user id n password is Correct.
	/*	if(!validateUser(lBean.getUsrid(),lBean.getUsrpwd()))
		{
			errors.rejectValue("errors", "error.invalidIdPwd", "Invalid User id or Password");
		}*/
	}
	
	/* This method has to be modified later to check values against the database.
	 * 
	 */
	public boolean validateUser(String userid, String pwd)
	{
		
		return true;
	}
}